﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using attendance.L3Bussobject;
using System.Data;
using attendance.L1Dataaccess;

namespace attendance.L2Busslogic
{
    public class qiandaoBL
    {
        public static qiandaoOB Getmark()     //获取数据库中的单条数据
        {
            string commandtext = "select * from qiandao ";
            qiandaoOB myword = new qiandaoOB();       //数据库对象
            myword.q_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = qiandaoDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;


            myword.q_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.q_numb = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.q_date = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.q_ip = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.q_photo = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.photo = ds.Tables[0].Rows[i][6].ToString().Trim();

            return myword;
        }
        public static qiandaoOBList GetmarkAll()       //获取数据库中的所有记录
        {
            string commandtext = "select * from qiandao";
            qiandaoOBList tempList = null;
            tempList = new qiandaoOBList();
            DataSet ds = null;
            ds = qiandaoDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                qiandaoOB myword = new qiandaoOB();

                myword.q_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.q_numb = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.q_date = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.q_ip = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.q_photo = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.photo = ds.Tables[0].Rows[i][6].ToString().Trim();


                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static bool Addfill(qiandaoOB myword)      //添加纪录
        {
            string ss = "INSERT INTO qiandao (q_name,q_numb,q_date,q_ip,q_photo,photo)VALUES('";
            ss = ss + myword.q_name.Trim() + "','";
            ss = ss + myword.q_numb.Trim() + "','";
            ss = ss + myword.q_date.Trim() + "','";
            ss = ss + myword.q_ip.Trim() + "','";
            ss = ss + myword.q_photo.Trim() + "','";
            ss = ss + myword.photo.Trim() + "')";

            return qiandaoDB.AddDeleteItem(ss);
        }

        public static qiandaoOB Getwordsingle(string nameq)      //按姓名查找
        {
            string commandtext = "select * from qiandao where q_name='" + nameq.Trim() + "'";
            qiandaoOB myword = new qiandaoOB();
            myword.q_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = qiandaoDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.ID = ds.Tables[0].Rows[i][0].ToString().Trim();
            myword.q_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.q_numb = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.q_date = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.q_ip = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.q_photo = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.photo = ds.Tables[0].Rows[i][6].ToString().Trim();

            return myword;
        }
        public static bool Savemark(qiandaoOB myword)     //修改记录
        {
            string commandtext = "update qiandao set  q_name='";
            commandtext = commandtext + myword.q_name.Trim() + "', q_numb='";
            commandtext = commandtext + myword.q_numb.Trim() + "',q_date='";
            commandtext = commandtext + myword.q_date.Trim() + "',q_ip='";
            commandtext = commandtext + myword.q_ip.Trim() + "',q_photo='";
            commandtext = commandtext + myword.q_photo.Trim() + "',photo='";
            commandtext = commandtext + myword.photo.Trim() + "' where ID=";
            commandtext = commandtext + myword.ID.Trim();
            return qiandaoDB.AddDeleteItem(commandtext);
        }
        public static bool deleteword(string name)      //删除记录
        {
            string ss = "delete from qiandao where q_name='" + name.Trim() + "'";
            return qiandaoDB.AddDeleteItem(ss);
        }
        public static bool deleteAll()      //删除记录
        {
            string ss = "delete from qiandao '";
            return qiandaoDB.AddDeleteItem(ss);
        }
        public static bool deletephoto(string name,string q_photo)
        {
            string ss = "delete from qiandao where q_name='" + name.Trim() + "'" + " and q_photo='" + q_photo.Trim() + "'";
            return qiandaoDB.AddDeleteItem(ss);
        }
    }
}